var gulp = require('gulp'),
    clean = require('gulp-clean'),
    watch = require('gulp-watch'),
    browserSync = require('browser-sync').create(),
    reload = browserSync.reload,
    sass = require('gulp-ruby-sass');

// 编译 sass
gulp.task('sass', function () {
    return sass('dist/sass/main.scss')
        .pipe(gulp.dest('dist/css'))
        .pipe(reload({ stream: true }));
});

// 启动 webserver
gulp.task('server', ['sass'], function () {
    browserSync.init({
        // files: ['**'],
        server: {
            baseDir: 'dist', // 设置服务器的根目录
            // index: 'index.html' // 指定默认打开的文件
        },
        // port: 8080 // 指定访问服务器的端口号
    });

    gulp.watch('*.scss', { cwd: 'dist/sass' }, ['sass']);
    gulp.watch('*.js', { cwd: 'dist/js' }, reload);
    gulp.watch('*.html', { cwd: 'dist' }, reload);
});

gulp.task('default', ['server']);